package com.bkgrands.fpmu.classes;

import android.content.Intent;
import android.os.Handler;
import android.util.Log;

import com.bkgrands.fpmu.Adapters.MinorstagesAdapter;
import com.bkgrands.fpmu.Adapters.MstagesAdapter;
import com.bkgrands.fpmu.Adapters.SiteAdapter;
import com.bkgrands.fpmu.R;
import com.bkgrands.fpmu.Retro.APIClient;
import com.bkgrands.fpmu.Retro.APIInterface;
import com.bkgrands.fpmu.activities.HomeActivity;
import com.bkgrands.fpmu.activities.LoginActivity;
import com.bkgrands.fpmu.activities.MinorStagesActivity;
import com.jeevandeshmukh.glidetoastlib.GlideToast;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import static android.support.constraint.Constraints.TAG;

/**
 * Created by jeff on 7/11/19.
 */

public class StaticFarm  {
    public static CMResponse responseAtLogin;
    public static Payload currentSite;
    public static Mstage currentMStage;
    public static MinorStage currentMinorStage;
    public static Progress currentPhotos;
    public static Photo currentImages;
    public static UploadPhotoResponse currentphotoResponse;
    public static ThePhoto currentPhotoUpload;
    public static SetProgressResponse currentprogressressponse;
    public static String currentPhotoToUpload;
    public static ThisStage currenntupdatedStage;
    public static String user_name;
    public static String user_password;

    public static SiteAdapter siteAdapter;
    public static MstagesAdapter mstageAdapter;
    public static MinorstagesAdapter minorStageAdapter;
    public static MinorStagesActivity minorStageActivity;
    public static List<MinorStage> currentMinorStagesPlural;

    public static void refreshContent() {
        ArrayList<String> al = new ArrayList<>();
    }

    public static void updateStaticVariables(CMResponse loginResponse) {
        List<Payload> payload = loginResponse.getPayload();
        for (Payload site :
                payload) {
            if(site.getId().equals(StaticFarm.currentSite.getId())){
                StaticFarm.currentSite = site;
                // With current site in please lets get the current major stage
                List<Mstage> mstages = site.getMstages();
                for (Mstage major_stage: mstages) {
                    if(major_stage.getId().equals(StaticFarm.currentMStage.getId())){
                        StaticFarm.currentMStage = major_stage;
                        // With the mStage lets get the current minor stage
                        List<MinorStage> minorStages = major_stage.getMinorStages();
                        StaticFarm.currentMinorStagesPlural = (List<MinorStage>)((ArrayList<MinorStage>)minorStages).clone();
                        for (MinorStage minor_stage: minorStages) {

                            if(StaticFarm.currentMinorStage.getId().equals(minor_stage.getId())){
                                StaticFarm.currentMinorStage =  minor_stage;

                                // At this point we have update all the static vars


                            }
                        }
                    }
                }
            }

        }
    }

    public static void updateAdapters() {
        List<MinorStage> currentMinorStagesPlural = (List<MinorStage>) ((ArrayList<MinorStage>)StaticFarm.currentMinorStagesPlural).clone();

        StaticFarm.siteAdapter.updateData(StaticFarm.responseAtLogin.getPayload());
        List<MinorStage> currentMinorStagesPlural1 = StaticFarm.currentMinorStagesPlural;
        StaticFarm.mstageAdapter.updateData(StaticFarm.currentSite.getMstages());
        List<MinorStage> currentMinorStagesPlural2 = StaticFarm.currentMinorStagesPlural;
        StaticFarm.minorStageAdapter.updateData(currentMinorStagesPlural);
        Log.d(TAG, "updateAdapters: see me");
        Log.i(TAG, "updateAdapters: ");
    }
}
